<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>选课系统-注册界面</title>
		<link href="resources/css/bootstrap.css" rel="stylesheet">
		<link href="resources/css/bootstrap-responsive.css" rel="stylesheet">
		<link href="resources/css/styles.css" rel="stylesheet">
		<script src="resources/js/jquery.js"></script>
		<script>
	$(function() {
		$("button").click(
				function() {
					var name = $("input:eq(0)").val();
					var schoolNo = $("input:eq(1)").val();
					var pwd = $("input:eq(2)").val();
					var pwdAgain = $("input:eq(3)").val();
					var email = $("input:eq(4)").val();
					var phone = $("input:eq(5)").val();
					var role = $("select").val();
					var sex = $("input[name='sex']:checked").val();

					if (pwd != pwdAgain) {
						alert('两次输入的密码不相同，请重新输入！');
						$("input:eq(2)").val("");
						$("input:eq(3)").val("");
					} else {
						if (name == "" || schoolNo == "" || pwd == ""
								|| email == "" || phone == "" || role == ""
								|| sex == "") {
							alert("请将信息填写完整！");
						} else {
							$.ajax({
								url : "add.do",
								type : "post",
								data : {
									"name" : name,
									"schoolNo" : schoolNo,
									"pwd" : pwd,
									"email" : email,
									"phone" : phone,
									"role" : role,
									"sex" : sex
								},
								dataType : "json",
								success : function(json) {
									if (json) {
										alert("register successfully");
									} else {
										alert("register failed");
									}
								}
							});
						}
					}
				});
		$("input:button").click(function() {
			window.open("main.do");
		});
	});
</script>
	</head>

	<body>
		<div class="container-fluid">
			<form class="form-signin" action="add.do" method="post">
				<h2 class="form-signin-heading">
					Fill out in detail

				</h2>
				<input name="name" type="text" placeholder="Username"
					class="input-block-level">
				<input name="schoolNo" type="text" placeholder="SchoolNO"
					class="input-block-level">
				<input name="pwd" type="password" placeholder="Password"
					class="input-block-level">
				<input name="passwordAgain" type="password"
					placeholder="PasswordAgain" class="input-block-level">
				<input name="email" type="text" placeholder="Email"
					class="input-block-level">
				<input name="phone" type="text" placeholder="Phone"
					class="input-block-level">
				<div style="min-height: 30px">
					<select name="role" style="width: 100%; font-size: 16px;">
						<option>
							please choose your identity
						</option>
						<option value="1">
							student
						</option>
						<option value="0">
							teacher
						</option>
					</select>
				</div>
				<div style="min-height: 30px; font-size: 16px;">
					<input type="radio" value="0" name="sex" />
					male
					<input type="radio" value="1" name="sex" style="margin-left: 10px" />
					female
				</div>
				<button type="button" class="btn btn-large btn-primary"
					style="margin-top: 10px">
					register
				</button>
				<input type="button" class="btn btn-large btn-primary"
					value="return" style="margin-top: 10px; margin-left: 10px" />

			</form>
		</div>

	</body>
</html>